﻿<div class="layui-card" id="lg-ExamList">
    <div class="layui-card-header"><i class="fa fa-home fa-fw"></i>考试安排</div>
    <div class="layui-card-body" id="">
        <div class="lg-form-box">
            <table class="layui-hide" id="ExamList" lay-filter="ExamList"></table>
        </div>
        <!-- 内容主体区域结束 -->
    </div>
</div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add"><i class="fa fa-plus fa-fw"></i>添加</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="refresh"><i class="fa fa-refresh fa-fw"></i>刷新</button>
    </div>
</script>
<script type="text/html" id="btTpl">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit" title="编辑"><span class="fa fa-pencil-square-o fa-fw "></span></a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="del" title="删除"><span class="fa fa-trash-o fa-fw"></span></a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="config" title="设置"><span class="fa fa-cog fa-fw"></span></a>
</script>
<script>
    frame.createPage({
        mounted: function() {
            var page = this;
            page.vm = Vue.createApp({
                data() {
                    return {

                    }
                },
                mounted: function() {
                    this.TableRender();
                },
                methods: {
                    showPage: function() {
                        Pages.RedirectTo({
                            url: "/lgm/apply/Exam/List",
                            title: "考试安排"
                        })
                    },
                    TableRender: function() {
                        layui.use(['table', 'element', 'form'], function() {
                            var table = layui.table;
                            var form = layui.form;
                            form.render();
                            page.laytable = table.render({
                                elem: '#ExamList'
                                , url: '/api/sys/apply/GetExamList'
                                , toolbar: '#toolbar' //开启头部工具栏，并为其绑定左侧模板
                                , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                                , cols: [[
                                     {
                                        field: 'id', title: '#', width: 60, templet: function(d) {
                                            return d.LAY_TABLE_INDEX + 1
                                        }
                                    }
                                    , { field: 'Title', title: '考试名称', width: 250 }
                                    , { field: 'PlanTitle', title: '计划名称'}
                                    , {
                                        field: 'Project', title: '科目', width: 150  }
                                    
                                    , { field: 'StudentCount', title: '人数', width: 60, align: "center" }
                                    , { field: 'AddTime', title: "添加日期", width: 120 }
                                    , {
                                        field: 'IsOpen', title: '状态', width: 100, align: "center", templet: function(d) {
                                            return laySwitch.render(d.IsOpen, 'open')
                                        }
                                    }
                                    , { fixed: 'right', title: '操作', toolbar: '#btTpl', width: 260 }
                                ]]
                                , page: true
                            });
                            table.on('toolbar(ExamList)', function(obj) {
                                var checkStatus = table.checkStatus(obj.config.id);
                                switch (obj.event) {
                                    case 'add':
                                        frame.NavigateTo({
                                            url: "/lgm/apply/Exam/add",
                                            title: "添加考试"
                                        })
                                        break;
                                    case 'refresh':
                                        page.laytable.reload();
                                        break;
                                };
                            })
                            table.on('tool(ExamList)', function(obj) {
                                var data = obj.data;
                                switch (obj.event) {
                                    case 'edit':
                                        frame.NavigateTo({
                                            url: "/lgm/apply/Exam/edit/" + data.Id,
                                            title: "编辑考试"
                                        })
                                        break;
                                     case 'config':
                                        frame.NavigateTo({
                                            url: "/lgm/apply/Exam/info/" + data.Id,
                                            title: "考试设置"
                                        })
                                        break;
                                    case 'open':
                                        laySwitch.do({
                                            obj: obj,
                                            key: "IsOpen",
                                            url: "/api/sys/apply/EditExam",
                                            refresh: function() {
                                                page.laytable.reload();
                                            }
                                        })
                                        break;
                                    case "del":
                                        layer.confirm('真的删除行么', function(index) {
                                            lg.request({
                                                url: "/api/sys/apply/deleteExam",
                                                method: "post",
                                                data: { id: data.Id },
                                                success: res => {
                                                    if (res.code == 0) {
                                                        obj.del();
                                                    }
                                                }
                                            })
                                            layer.close(index);
                                        });
                                        break;
                                };
                            })
                        });
                    },
                    reload: function() {
                        this.laytable.reload();
                    }
                },
                updated: function() {
                    layui.form.render();
                }
            }).mount("#lg-ExamList")
        }
    }).mount();

</script>